home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / GX Libraries / RoundRectLibrary.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-31  |  3.5 KB  |  100 lines  |  [TEXT/MPS ]

  1.  
  2. /*
  3.     File:        RoundRectLibrary.c
  4.  
  5.     Contains:    graphics libraries - rounded corner gxRectangle routines
  6.     
  7.     Written by:    Cary Clark, Georgiann Delaney, Michael Fairman, Dave Good, Robert Johnson, Keith McGreggor, Oliver Steele, David Van Brink, Chris Yerga
  8.     
  9.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  10.  
  11.     Change History (most recent first):
  12.  
  13.          <1>      1/9/95    JD        First checked in.
  14. */
  15.  
  16. #include "GraphicsLibraries.h"
  17.  
  18. static void RoundRectPath(Fixed *contourData, register const gxRectangle *r, const gxPoint *ovalSize)
  19. {
  20.     NilParamReturn(contourData);
  21.     NilParamReturn(r);
  22.     NilParamReturn(ovalSize);
  23.     {   register Fixed *contourWalker = contourData;
  24.         register Fixed offX = ovalSize->x/2;
  25.         register Fixed offY = ovalSize->y/2;
  26.         register Fixed maxX = (r->right - r->left) / 2;
  27.         register Fixed maxY = (r->bottom - r->top) / 2;
  28.         
  29.         if (offX > maxX)
  30.             offX = maxX;
  31.         if (offY >  maxY)
  32.             offY = maxY;
  33.         *contourWalker++ = 12;              /* twelve points, all in all            */
  34.         *contourWalker++ = 0x49200000;      /* one on, one off, one on... times 4       */
  35.     
  36.         *contourWalker++ = r->left;         /* 1st pt (top left corner)         */
  37.         *contourWalker++ = r->top + offY;
  38.         *contourWalker++ = r->left;         /* 2nd pt                           */
  39.         *contourWalker++ = r->top;
  40.         *contourWalker++ = r->left + offX;      /* 3rd pt                           */
  41.         *contourWalker++ = r->top;
  42.     
  43.         *contourWalker++ = r->right - offX;     /* 4th pt (top right corner)            */
  44.         *contourWalker++ = r->top;
  45.         *contourWalker++ = r->right;            /* 5th pt                           */
  46.         *contourWalker++ = r->top;
  47.         *contourWalker++ = r->right;            /* 6th pt                           */
  48.         *contourWalker++ = r->top + offY;
  49.     
  50.         *contourWalker++ = r->right;            /* 7th pt (bottom right corner)         */
  51.         *contourWalker++ = r->bottom - offY;
  52.         *contourWalker++ = r->right;            /* 8th pt                           */
  53.         *contourWalker++ = r->bottom;
  54.         *contourWalker++ = r->right - offX;     /* 9th pt                           */
  55.         *contourWalker++ = r->bottom;
  56.     
  57.         *contourWalker++ = r->left + offX;      /* 10th pt (bottom left corner)         */
  58.         *contourWalker++ = r->bottom;
  59.         *contourWalker++ = r->left;         /* 11th pt                      */
  60.         *contourWalker++ = r->bottom;
  61.         *contourWalker++ = r->left;         /* 12th pt                      */
  62.         *contourWalker++ = r->bottom - offY;
  63.     }
  64. }
  65.  
  66. gxShape NewRoundRect(const gxRectangle *rectData, const gxPoint *ovalSize)
  67. {
  68.     long newContour[26];
  69.  
  70.     NilParamReturnNil(rectData);
  71.     NilParamReturnNil(ovalSize);
  72.  
  73.     RoundRectPath(newContour, rectData, ovalSize);
  74.     return NewPath((gxPath *) newContour);
  75. }
  76.  
  77. void SetRoundRect(gxShape aShape, const gxRectangle *rectData, const gxPoint *ovalSize)
  78. {
  79.     long newContour[26];
  80.  
  81.     NilShapeReturn(aShape);
  82.     NilParamReturn(rectData);
  83.     NilParamReturn(ovalSize);
  84.  
  85.     RoundRectPath(newContour, rectData, ovalSize);
  86.     SetPath(aShape, 0, (gxPath *) newContour);
  87. }
  88.  
  89. void DrawRoundRect(const gxRectangle *bounds, const gxPoint *ovalSize, gxShapeFill fill)
  90. {   
  91.     NilParamReturn(bounds);
  92.     NilParamReturn(ovalSize);
  93.     {   register gxShape newShape = NewRoundRect(bounds, ovalSize);
  94.     
  95.         GXSetShapeFill(newShape, fill);
  96.         GXDrawShape(newShape);
  97.         GXDisposeShape(newShape);
  98.     }
  99. }
  100.